package com.im.app.controller;

import com.im.app.service.ConversationsService;
import com.im.app.utils.Response;
import com.im.app.utils.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping(value = "/conversations")
public class ConversationsController {

    @Resource
    private ConversationsService conversationsService;

    /**
     * 会话置顶
     *
     * */
    @RequestMapping(value ="/updateIsPinned",method=RequestMethod.POST)
    public ResponseResult updateIsPinned(Integer isPinned,String conversationId) {

        int result = conversationsService.updateIsPinned(isPinned,conversationId);
        if(result>0){
            return Response.makeOKRsp("置顶成功");
        }else{
            return Response.makeErrRsp("置顶失败");
        }

    }


    /**
     * 未读数清除
     *
     * */
    @RequestMapping(value ="/clearUnreadCount",method=RequestMethod.POST)
    public ResponseResult clearUnreadCount(String conversationId) {

        int result = conversationsService.clearUnreadCount(conversationId);
        if(result>0){
            return Response.makeOKRsp();
        }else{
            return Response.makeErrRsp("异常");
        }

    }

}
